package org.liveboardgames.agricola.control.commands
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import mx.collections.ListCollectionView;
	import mx.controls.Alert;
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	import org.liveboardgames.agricola.control.delegates.CreateGameDelegate;
	import org.liveboardgames.agricola.control.delegates.action.AgricolaActionController;
	import org.liveboardgames.agricola.control.events.CreateGameEvent;
	import org.liveboardgames.agricola.model.AgricolaModelLocator;
	import org.liveboardgames.agricola.model.enums.GameTypeEnum;
	import org.liveboardgames.agricola.model.enums.ResourceTypeEnum;
	import org.liveboardgames.agricola.vo.Game;
	import org.liveboardgames.agricola.vo.player.Player;
	import org.liveboardgames.common.dictionary.collections.HashCollection;

	public class CreateGameCommand implements ICommand, IResponder
	{
		public function CreateGameCommand()
		{
		}

		public function execute(event:CairngormEvent):void
		{
			var delegate:CreateGameDelegate = new CreateGameDelegate(this);
			var createGameEvent:CreateGameEvent = CreateGameEvent(event);
			delegate.createGame(createGameEvent.players, GameTypeEnum.FAMILY);
		}

		public function result(event:Object):void
		{
			var model:AgricolaModelLocator = AgricolaModelLocator.getInstance();
			model.game = ResultEvent(event).result as Game;
			model.actionController = new AgricolaActionController(model.game);
		}

		public function fault(info:Object):void
		{
			var faultEvent:FaultEvent = FaultEvent(info);
			Alert.show("Error when trying to create the game", "Error");
		}

	}
}